#ifndef SYSTEMCALL_H_
#define SYSTEMCALL_H_

#include<map>
#include "FileSystem.h"
#include "FileTableEntry.h"

class SystemCall
{

public:
	/**
	 * Notice : inode 0 is root
	 * all path have to start with root/....
	 *
	 *
	 */
	FileSystem *fileSys;

	map<int,FileTableEntry> fileTable;

	SystemCall();

	SystemCall(int _diskSize, int _blockSize, int _numOfNodes);

	void initRoot();

	virtual ~SystemCall();

	//*INTERFACE FUNCTIONS*//

	/*if you want soft link you better use createSoftLink
	 *
	 *
	 *
	 */
	int MakeFile(char * fileName , char type , bool premission);

	int MakeHLink(char * targetFileName , char * fileName);

	int MakeDir(char * fileName);

	int RmDir(char * dirName);

	int RmFile(char * fileName);

	int ls(char* dirName , char* buffer);

	int Open(char* fileName , bool premission);

	int Close(int fd);

    int Seek(int fd, int location);

    int Read(int fd, int nBytes , char * buffer);

    int Write(int fd , int nBytes , char * buffer);
    /**
     * asumes that newdset is all file path ans parendDir is all file path
     * return 1 if true or -1 else
     *
     */
    int moveFile(char* parendDir , char * new_dest);

    bool isDir(char * address);



	//*HELPING FUNCTIONS*//

	/**
	 * creates a shourtcut/softLiink file with L in type
	 */
	int createSoftLink(char* shoutcutPlace,char* fileName);

	int fileTableSize();

	void pathTokenizer(char* path, vector<string> &results);

	/*
	 * returning the inode of the librery of the node
	 * else if exesitent file or not existent path return -1;
	 * addOrRemove if 1 means add if -1 means remove
	 *
	 */
	int checkAndSetDir(string path, char flag );

	void addInodeToDir(int dir,int inode,char* fileName ,list<pair<int , char*> >* dirList);

	int getCurrentDir(string path , vector<string> results);
	/**
	 * return -1 if inode is not existent
	 */
	int deleteInodeFromDir(int dir , int inode);

	int newFTE(int inode , bool premission);

	int deleteFile(int inode);

	int cleenName(char* name);

	int lsHelper(list<pair<int,char*> >* dirList , char * buffer);

	int fdToInode(int fd);

	int fdToOffset(int fd);

	bool fdToPremission(int fd);

	int getInodeFromPath(char* path);

	void incHlink(int inode);

	//Printing functions //

	void printDir(char* dirName);
	void printList(list<pair<int,char*> >* dirList);
};

#endif /*SYSTEMCALL_H_*/
